<?php

namespace Modules\WeChat\Http\Controllers;

use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Request;
use Modules\WeChat\Service\AccountService;

class WeChatController extends Controller
{

    /**
     * 欢迎页面
     * @return Response
     */
    public function welcome()
    {
        return view('wechat::welcome');
    }

    /**
     * Display a listing of the resource.
     * @return Response
     */
    public function index()
    {
        $s_openid = get_openid();
//        $url = 'http://jinwechat.7deer.cn/wechat_index1?wat_token='.$s_openid;
//        header("Location: $url");
////        return view('wechat::index');
        $s_http_referer = session_get('wechat_http_referer');
        $arr_data = ['token'=>$s_openid,'http_referer'=>$s_http_referer];
        return view('wechat::index',$arr_data );

    }

    /**
     * Display a listing of the resource.
     * @return Response
     */
    public function me()
    {
//        $arr_wechat_user = wechat_user();
//        $arr_data = [
//          ''
//        ];
        return  hello_success('成功');
    }

    public function center()
    {
        dd(999);
  
        return view('wechat::index');
    }

    /**
     * 绑定账号
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function account_binding(){
        try {
            $arr_input = Request::input();
            $arr_input['openid'] = get_wat_token();
            $res = AccountService::binding($arr_input);
            return  $res;
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }

    }

    /**
     * 解绑账号
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function account_unbinding(){
        try {
            $s_openid = get_wat_token();
            $res = AccountService::unbinding($s_openid);
            return  $res;
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }

    }

}
